package edu.wong.pro.action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

import edu.wong.pro.iservice.IIndiAct;

public class IndiActAction extends ActionSupport{

	private IIndiAct indiAct;
	
	
	public IIndiAct getIndiAct() {
		return indiAct;
	}


	public void setIndiAct(IIndiAct indiAct) {
		this.indiAct = indiAct;
	}

    //发布个人活动
	public String relIndiAct(){
		HttpServletRequest request = (HttpServletRequest) ServletActionContext.getRequest();
	    String indiTheme = request.getParameter("indiTheme");
	    String indiContent = request.getParameter("indiContent");
		String indiDate = request.getParameter("indiDate");
	    String indiAddition = request.getParameter("indiAddition");	
	    indiAct.relIndiAct(indiTheme, indiContent, indiDate, indiAddition);
	    return "ok";
	}
	
	//获取个人活动
	public void getMyIndiActList() throws IOException{
		HttpServletResponse response = (HttpServletResponse) ServletActionContext.getResponse();
		response.setCharacterEncoding("utf-8");
		PrintWriter writer = response.getWriter();
		writer.print(indiAct.getMyIndiAct());
		writer.flush();
		writer.close();	
	}
	
	//通过ID获取个人活动
		public void getIndiActByID() throws IOException{
			HttpServletRequest request = (HttpServletRequest)ServletActionContext.getRequest();
			String indiActId = request.getParameter("individualId");
			HttpServletResponse response = (HttpServletResponse) ServletActionContext.getResponse();
			response.setCharacterEncoding("utf-8");
			PrintWriter writer = response.getWriter();
			writer.print(indiAct.getIndiActByID(indiActId));
			writer.flush();
			writer.close();	
		}
	
	//获取前10条最新个人活动
	public void getTopIndiAct() throws IOException{
		HttpServletResponse response = (HttpServletResponse) ServletActionContext.getResponse();
		response.setCharacterEncoding("utf-8");
		PrintWriter writer = response.getWriter();
		writer.print(indiAct.getTopIndiAct());
		writer.flush();
		writer.close();	
	}
	
}
